package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250124093328CreatePermissionsTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250124093328CreatePermissionsTable) Signature() string {
	return "20250124093328_create_permissions_table"
}

// Up Run the migrations.
func (r *M20250124093328CreatePermissionsTable) Up() error {
	if !facades.Schema().HasTable("permissions") {
		return facades.Schema().Create("permissions", func(table schema.Blueprint) {
			table.ID()
			//table.Integer("tenant_id").Nullable().Default(0).Unsigned().Comment("租户id")
			table.String("perm_name").Comment("权限名")
			//table.TinyInteger("perm_type").Default(1).Comment("1 目录 2 菜单 3 按钮")
			table.String("perm_key").Comment("唯一标识符")
			table.String("route").Nullable().Comment("路由")
			//table.String("frontend_route").Nullable().Comment("前端路由")
			table.Integer("parent_id").Default(0).Comment("父权限ID")
			//table.TinyInteger("keepalive").Default(1).Comment("1 缓存 2 不缓存")
			//table.TinyInteger("status").Default(1).Comment("1 显示 2 隐藏")
			table.BigInteger("sort").Nullable().Default(0).Comment("排序")
			table.Timestamps()
			table.SoftDeletes()

			table.Unique("perm_key", "deleted_at")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250124093328CreatePermissionsTable) Down() error {
	return facades.Schema().DropIfExists("permissions")
}
